//
//  ViewController.m
//  WDBMS
//
//  Created by YeJary on 2025/5/9.
//

#import "ViewController.h"
#import <Masonry/Masonry.h>
#import "BMSAuthSDK.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewWillAppear:(BOOL)animated {
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createUI];
    // Do any additional setup after loading the view.
}

- (void)createUI {
    UIButton *PrivacyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [PrivacyBtn setTitle:@"隐私协议" forState:UIControlStateNormal];
    [PrivacyBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [PrivacyBtn setBackgroundColor:[UIColor blueColor]];
    [PrivacyBtn.layer setCornerRadius:5.f];
    [PrivacyBtn addTarget:self action:@selector(PrivacyBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:PrivacyBtn];
    
    [PrivacyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(100);
        make.left.mas_equalTo(30);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *RealNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [RealNameBtn setTitle:@"实名认证" forState:UIControlStateNormal];
    [RealNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [RealNameBtn setBackgroundColor:[UIColor blueColor]];
    [RealNameBtn.layer setCornerRadius:5.f];
    [RealNameBtn addTarget:self action:@selector(RealNameBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:RealNameBtn];
    
    [RealNameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.top.mas_equalTo(PrivacyBtn);
        make.width.height.mas_equalTo(PrivacyBtn);
    }];
    
    UIButton *FetchGameConfigBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [FetchGameConfigBtn setTitle:@"初始化配置" forState:UIControlStateNormal];
    [FetchGameConfigBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [FetchGameConfigBtn setBackgroundColor:[UIColor blueColor]];
    [FetchGameConfigBtn.layer setCornerRadius:5.f];
    [FetchGameConfigBtn addTarget:self action:@selector(FetchGameConfigBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:FetchGameConfigBtn];
    
    [FetchGameConfigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(PrivacyBtn.mas_bottom).offset(50);
        make.left.mas_equalTo(30);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(50);
    }];
    
    UIButton *holidayNameBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [holidayNameBtn setTitle:@"假期列表" forState:UIControlStateNormal];
    [holidayNameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [holidayNameBtn setBackgroundColor:[UIColor blueColor]];
    [holidayNameBtn.layer setCornerRadius:5.f];
    [holidayNameBtn addTarget:self action:@selector(holidayNameBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:holidayNameBtn];
    
    [holidayNameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-30);
        make.top.mas_equalTo(RealNameBtn.mas_bottom).offset(50);
        make.width.height.mas_equalTo(PrivacyBtn);
    }];
    
    UIButton *IPBlockConfigBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [IPBlockConfigBtn setTitle:@"IP屏蔽列表" forState:UIControlStateNormal];
    [IPBlockConfigBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [IPBlockConfigBtn setBackgroundColor:[UIColor blueColor]];
    [IPBlockConfigBtn.layer setCornerRadius:5.f];
    [IPBlockConfigBtn addTarget:self action:@selector(IPBlockConfigBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:IPBlockConfigBtn];
    
    [IPBlockConfigBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(holidayNameBtn.mas_bottom).offset(50);
        make.left.mas_equalTo(30);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(50);
    }];
}



#pragma mark ---------- click handle ------------

- (void)PrivacyBtnHandle:(UIButton *)sender {
    BMSAuthSDK *auth = [[BMSAuthSDK alloc]init];
    [auth showPrivacyPopupWithCompletion:^(BOOL agreed) {
        if (agreed){
            NSLog(@"已同意隐私协议");
        } else {
            NSLog(@"未同意隐私协议");
        }
    }];
}

- (void)RealNameBtnHandle:(UIButton *)sender {
    BMSAuthSDK *auth = [[BMSAuthSDK alloc]init];
    [auth showRealnamePopupWithCompletion:^(BOOL success) {
            
    }];
}

- (void)FetchGameConfigBtnHandle:(UIButton *)sender {
    [[BMSAuthSDK shareInstance]initSDKCompletion:^(BOOL success,
                                                   BOOL privacyAgreed,
                                                   BOOL trackingAuthorized,
                                                   BOOL didRealname,
                                                   NSString * _Nonnull uuid) {
        if (success) {
            NSLog(@"✅ 初始化完成, uuid: %@", uuid);
        } else {
            NSLog(@"❌ 初始化失败（用户拒绝授权）");
        }
    }];
}

- (void)holidayNameBtnHandle:(UIButton *)sender {
    [[BMSAuthSDK shareInstance]fetchOfficialHolidaysWithSuccess:^(id  _Nonnull responseObject) {
        NSLog(@"获取节假日列表：\n response = %@",responseObject);

    } failure:^(NSError * _Nonnull error) {
        NSLog(@"获取节假日列表失败\n %@",error);

    }];
}

- (void)IPBlockConfigBtnHandle:(UIButton *)sender {
    [[BMSAuthSDK shareInstance]checkIPBlockStatusWithAppName:@"123" channel:@"weixin" version:@"1.0.0" ip:@"" success:^(NSDictionary * _Nonnull response) {
        NSLog(@"获取IP 屏蔽列表：\n response = %@",response);
    } failure:^(NSError * _Nonnull error) {
        NSLog(@"获取IP 屏蔽列表失败\n %@",error);

    }];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    NSLog(@"点击：%@",NSStringFromClass([self class]));
}

@end
